package edu.rmit.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import edu.rmit.contant.TableConstant;
import edu.rmit.dao.ISystemInfoDAO;
import edu.rmit.domain.SystemInfo;
import edu.rmit.util.DBManager;

/**
 * This interface implement the system info operation. Link get the welcome information
 * and the operation instructions.
 * @author Joey George
 * @version 1.0
 */
public class SystemInfoDAOImpl implements ISystemInfoDAO {

	/**
	 * The database connection management class.
	 */
	private DBManager dbManager = null;

	/**
	 * The constructor without parameter to initialize a database connection.
	 */
	public SystemInfoDAOImpl() {
		dbManager = new DBManager();
	}

	/**
	 * This method implement to get a system information.
	 * @return The welcome information and the operation isntructions.
	 */
	@Override
	public SystemInfo getSystemInfo() {
		String sqlString = "select * from " + TableConstant.SYSTEM_INFO_TABLE;
		Connection connection = dbManager.getConnection();
		PreparedStatement preparedState = null;
		ResultSet resultSet = null;
		SystemInfo systemInfo = new SystemInfo();
		try {
			preparedState = connection.prepareStatement(sqlString);
			resultSet = preparedState.executeQuery();
			if(resultSet.next()){
				systemInfo.setTitle(resultSet.getString("title"));
				systemInfo.setContent(resultSet.getString("content"));
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return systemInfo;
	}
}
